package com.whitedust.top40;

import com.whitedust.structure.ListNode;

/**
 * @author A
 * @since 2025/11/5 10:36
 */

public class Top36 {
    public ListNode removeNthFromEnd(ListNode head, int n) {
        ListNode dummy = new ListNode(0,head);
        ListNode slow = dummy;
        ListNode fast = dummy;
        for (int i = 0; i < n + 1; i++) {
            fast = fast.next;
        }
        while (fast != null) {
            slow = slow.next;
            fast = fast.next;
        }
        if(slow.next!=null){
            slow.next = slow.next.next;
        }
        return dummy.next;
    }
}
